using System;

namespace Aks.Deployment.SharePoint.Data
{
	/// <summary>
	/// Represents a CAML value node.
	/// </summary>
	/// <typeparam name="T">Type of the value.</typeparam>
	internal abstract class CamlValue<T> : CamlNode
	{
		/// <summary>CAML value format. Arguments include: (0) type, (1) value.</summary>
		protected const string CamlFormat = @"<Value Type='{0}'>{1}</Value>";

	
		/// <summary>
		/// Initializes a new instance of the <see cref="CamlValue&lt;T&gt;"/> class.
		/// </summary>
		/// <param name="value">The value.</param>
		protected CamlValue(T value) { this.Value = value; }


		/// <summary>
		/// Gets or sets the value.
		/// </summary>
		/// <value>The value.</value>
		public T Value { get; set; }


		/// <summary>
		/// Gets the type of the CAML value.
		/// </summary>
		/// <value>The type of the value.</value>
		protected abstract string CamlType { get; }


		/// <summary>
		/// Returns a string that represents the current CAML node.
		/// </summary>
		/// <returns>A string representation of the CAML node.</returns>
		public override string ToCaml()
		{
			return String.Format(CamlFormat, this.CamlType, this.Value);
		}
	}
}